package com.atguigu.study.test;

import lombok.extern.slf4j.Slf4j;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;

@Slf4j
public class SpringELDemo {
    public static void main(String[] args) {
        //log日志占位符
        log.info("你好{}","hello");
        //String.format占位符替换
        String hello = String.format("你好%s", "hello 尚硅谷");
        System.out.println(hello);
        //SpringELExpress表达式,#号后面的内容可以被具体值替换
        String var = "#userid";
        SpelExpressionParser spelExpressionParser = new SpelExpressionParser();
        Expression expression = spelExpressionParser.parseExpression(var);

        EvaluationContext context = new StandardEvaluationContext();
        context.setVariable("userid","1253");

        String s = expression.getValue(context).toString();

        System.out.println(s);


    }
}
